package config

import (
	"gopkg.in/yaml.v2"
	"log"
	"os"
)

type Config struct {
	Db       string `yaml:"db"`
	User     string `yaml:"user"`
	Url      string `yaml:"url"`
	Port     int    `yaml:"port"`
	Password string `yaml:"password"`
}

func (c *Config) ReadConfig(path string) (*Config, error) {
	yamlFile, err := os.ReadFile(path)
	if err != nil {
		log.Printf("Yaml get error %#v", err)
		return nil, err
	}
	err = yaml.Unmarshal(yamlFile, c)
	if err != nil {
		log.Fatal("Yaml Parse Error", err)
		return nil, err
	}
	return c, nil
}
